module.exports = function (app, router, jwt) {
    'use strict';
    var User = require('../../bookshelf/models/user.model');
    router.post('/token', function (req, res, next) {
        //获取登录用户和登录密码
        var loginName = req.body.userName;
        var loginPasswrod = req.body.userPassword;
        //从数据库中查询该用户，检查密码
        User.where('login_name', loginName).fetch().then(function(user) {
            if(user !== null)
            {
                if(loginPasswrod === user.get('login_passwd'))
                {
                    var jwtPayload = {
                        'userName':user.get('login_name')
                    };
                    var token = jwt.createToken(jwtPayload);

                    var ret = {
                        'jwtToken':token
                    };
                    res.status(200).send(ret);
                }else{
                    res.status(403).send('登录密码错误');
                }
            }else{
                res.status(403).send('用户不存在');
            }
        }).catch(function(err) {
            console.error(err);
        });
    });
};